< prev index next >

src/hotspot/os/linux/gc/z/zMountPoint_linux.cpp

Print this page




  66 
  67   free(line_filesystem);
  68 
  69   return line_mountpoint;
  70 }
  71 
  72 void ZMountPoint::get_mountpoints(const char* filesystem, ZArray<char*>* mountpoints) const {
  73   FILE* fd = fopen(PROC_SELF_MOUNTINFO, "r");
  74   if (fd == NULL) {
  75     ZErrno err;
  76     log_error_p(gc)("Failed to open %s: %s", PROC_SELF_MOUNTINFO, err.to_string());
  77     return;
  78   }
  79 
  80   char* line = NULL;
  81   size_t length = 0;
  82 
  83   while (getline(&line, &length, fd) != -1) {
  84     char* const mountpoint = get_mountpoint(line, filesystem);
  85     if (mountpoint != NULL) {
  86       mountpoints->add(mountpoint);
  87     }
  88   }
  89 
  90   free(line);
  91   fclose(fd);
  92 }
  93 
  94 void ZMountPoint::free_mountpoints(ZArray<char*>* mountpoints) const {
  95   ZArrayIterator<char*> iter(mountpoints);
  96   for (char* mountpoint; iter.next(&mountpoint);) {
  97     free(mountpoint);
  98   }
  99   mountpoints->clear();
 100 }
 101 
 102 char* ZMountPoint::find_preferred_mountpoint(const char* filesystem,
 103                                               ZArray<char*>* mountpoints,
 104                                               const char** preferred_mountpoints) const {
 105   // Find preferred mount point
 106   ZArrayIterator<char*> iter1(mountpoints);


 112       }
 113     }
 114   }
 115 
 116   // Preferred mount point not found
 117   log_error_p(gc)("More than one %s filesystem found:", filesystem);
 118   ZArrayIterator<char*> iter2(mountpoints);
 119   for (char* mountpoint; iter2.next(&mountpoint);) {
 120     log_error_p(gc)("  %s", mountpoint);
 121   }
 122 
 123   return NULL;
 124 }
 125 
 126 char* ZMountPoint::find_mountpoint(const char* filesystem, const char** preferred_mountpoints) const {
 127   char* path = NULL;
 128   ZArray<char*> mountpoints;
 129 
 130   get_mountpoints(filesystem, &mountpoints);
 131 
 132   if (mountpoints.size() == 0) {
 133     // No mount point found
 134     log_error_p(gc)("Failed to find an accessible %s filesystem", filesystem);
 135   } else if (mountpoints.size() == 1) {
 136     // One mount point found
 137     path = strdup(mountpoints.at(0));
 138   } else {
 139     // More than one mount point found
 140     path = find_preferred_mountpoint(filesystem, &mountpoints, preferred_mountpoints);
 141   }
 142 
 143   free_mountpoints(&mountpoints);
 144 
 145   return path;
 146 }
 147 
 148 const char* ZMountPoint::get() const {
 149   return _path;
 150 }


  66 
  67   free(line_filesystem);
  68 
  69   return line_mountpoint;
  70 }
  71 
  72 void ZMountPoint::get_mountpoints(const char* filesystem, ZArray<char*>* mountpoints) const {
  73   FILE* fd = fopen(PROC_SELF_MOUNTINFO, "r");
  74   if (fd == NULL) {
  75     ZErrno err;
  76     log_error_p(gc)("Failed to open %s: %s", PROC_SELF_MOUNTINFO, err.to_string());
  77     return;
  78   }
  79 
  80   char* line = NULL;
  81   size_t length = 0;
  82 
  83   while (getline(&line, &length, fd) != -1) {
  84     char* const mountpoint = get_mountpoint(line, filesystem);
  85     if (mountpoint != NULL) {
  86       mountpoints->append(mountpoint);
  87     }
  88   }
  89 
  90   free(line);
  91   fclose(fd);
  92 }
  93 
  94 void ZMountPoint::free_mountpoints(ZArray<char*>* mountpoints) const {
  95   ZArrayIterator<char*> iter(mountpoints);
  96   for (char* mountpoint; iter.next(&mountpoint);) {
  97     free(mountpoint);
  98   }
  99   mountpoints->clear();
 100 }
 101 
 102 char* ZMountPoint::find_preferred_mountpoint(const char* filesystem,
 103                                               ZArray<char*>* mountpoints,
 104                                               const char** preferred_mountpoints) const {
 105   // Find preferred mount point
 106   ZArrayIterator<char*> iter1(mountpoints);


 112       }
 113     }
 114   }
 115 
 116   // Preferred mount point not found
 117   log_error_p(gc)("More than one %s filesystem found:", filesystem);
 118   ZArrayIterator<char*> iter2(mountpoints);
 119   for (char* mountpoint; iter2.next(&mountpoint);) {
 120     log_error_p(gc)("  %s", mountpoint);
 121   }
 122 
 123   return NULL;
 124 }
 125 
 126 char* ZMountPoint::find_mountpoint(const char* filesystem, const char** preferred_mountpoints) const {
 127   char* path = NULL;
 128   ZArray<char*> mountpoints;
 129 
 130   get_mountpoints(filesystem, &mountpoints);
 131 
 132   if (mountpoints.length() == 0) {
 133     // No mount point found
 134     log_error_p(gc)("Failed to find an accessible %s filesystem", filesystem);
 135   } else if (mountpoints.length() == 1) {
 136     // One mount point found
 137     path = strdup(mountpoints.at(0));
 138   } else {
 139     // More than one mount point found
 140     path = find_preferred_mountpoint(filesystem, &mountpoints, preferred_mountpoints);
 141   }
 142 
 143   free_mountpoints(&mountpoints);
 144 
 145   return path;
 146 }
 147 
 148 const char* ZMountPoint::get() const {
 149   return _path;
 150 }
< prev index next >