Skip to contentSkip to conversation

conga/ricci/modules/storage ContentFS.cpp Cont ...

Cluster-devel [email protected] 1 participant 1 message Sep 26, 2006

lore
Share & tools
lore
#0 lore raw

CVSROOT: /cvs/cluster
Module name: conga
Changes by: kupcevic at sourceware.org 2006-09-26 03:02:57

Modified files:
ricci/modules/storage: ContentFS.cpp ContentFS.h ExtendedFS.cpp
ExtendedFS.h FSController.cpp Props.cpp Props.h SwapFS.cpp SwapFS.h defines.h

Log message:
storage module:
- unify mount handling
- add pretty names to filesystem types

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/ContentFS.cpp.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/ContentFS.h.diff?cvsroot=cluster&r1=1.5&r2=1.6
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/ExtendedFS.cpp.diff?cvsroot=cluster&r1=1.4&r2=1.5
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/ExtendedFS.h.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/FSController.cpp.diff?cvsroot=cluster&r1=1.5&r2=1.6
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/Props.cpp.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/Props.h.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/SwapFS.cpp.diff?cvsroot=cluster&r1=1.4&r2=1.5
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/SwapFS.h.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/ricci/modules/storage/defines.h.diff?cvsroot=cluster&r1=1.5&r2=1.6

ricci/modules/storage/ContentFS.cpp +185 -8
@@ -27,17 +27,23 @@
 #include "ContentNone.h"
 #include "BDFactory.h"
 #include "defines.h"
+#include "utils.h"
 
 
 using namespace std;
 
 
-ContentFS::ContentFS(const String& fs_name, const String& path) :
+#define ILLEGAL_MOUNT_CHARS   String(" <>?'\":;|}]{[)(*&^%$#@!~`+=")
+
+
+
+ContentFS::ContentFS(const String& path, 
+		     const String& name, 
+		     const String& module) :
   Content(CONTENT_FS_TYPE, path),
-  _name(fs_name)
-{
-  
-}
+  _name(name),
+  _module(module)
+{}
 
 ContentFS::~ContentFS()
 {}
@@ -85,7 +91,6 @@
 }
 
 
-
 XMLObject
 ContentFS::xml() const
 {
@@ -97,13 +102,185 @@
 
 
 
+void 
+ContentFS::mount_props_probe(const String& path,
+			     const String& fsname,
+			     Props& props)
+{
+  FstabLocker l;
+  MountHandler mh;
+  
+  // mountpoint
+  pair<unsigned int, unsigned int> maj_min = mh.maj_min(path);
+  list<Mountpoint> mounts = mh.mounts(maj_min);
+  String mountpoint;
+  if (mounts.size())
+    mountpoint = mounts.front().mountpoint;
+  list<String> ill_mnts = mh.used_dirs();
+  ill_mnts.remove(mountpoint);
+  // fstab
+  list<Mountpoint> fstabs = mh.fstabs(maj_min);
+  String fstabpoint;
+  if (fstabs.size())
+    fstabpoint = fstabs.front().mountpoint;
+  ill_mnts.remove(fstabpoint);
+  
+  
+  
+  bool mountable = mount_fs_supported(fsname);
+  props.set(Variable("mountable", mountable));
+  if (mountable)
+    props.set(Variable("mountpoint", 
+		       mountpoint, 
+		       0, 
+		       128, 
+		       ILLEGAL_MOUNT_CHARS, 
+		       ill_mnts));
+  if (mountable ||
+      !fstabpoint.empty())
+    props.set(Variable("fstabpoint", 
+		       fstabpoint, 
+		       0, 
+		       128, 
+		       ILLEGAL_MOUNT_CHARS, 
+		       ill_mnts));
+}
+
+void 
+ContentFS::mount_props_apply(const String& path,
+			     const String& fsname,
+			     const Props& old_props,
+			     const Props& new_props)
+{
+  FstabLocker l;
+  
+  // mountpoint
+  if (old_props.has("mountpoint")) {
+    String mnt_curr = old_props.get("mountpoint").get_string();
+    String mnt_new = new_props.get("mountpoint").get_string();
+    if (mnt_curr != mnt_new) {
+      MountHandler mh;
+      if (mnt_curr.size())
+	if (!mh.umount(path, mnt_curr))
+	  throw UMountError(mnt_curr);
+      if (mnt_new.size())
+	if (!mh.mount(path, mnt_new, fsname))
+	  throw String("mount failed");
+    }
+  }
+  
+  // fstab
+  if (old_props.has("fstabpoint")) {
+    String mnt_curr = old_props.get("fstabpoint").get_string();
+    String mnt_new = new_props.get("fstabpoint").get_string();
+    if (mnt_curr != mnt_new) {
+      MountHandler mh;
+      if (mnt_curr.size()) {
+	list<Mountpoint> l = mh.fstabs(mh.maj_min(path));
+	for (list<Mountpoint>::const_iterator iter = l.begin();
+	     iter != l.end();
+	     iter++)
+	  if (iter->mountpoint == mnt_curr)
+	    mh.fstab_remove(iter->devname, mnt_curr);
+      }
+      if (mnt_new.size())
+	mh.fstab_add(path, mnt_new, fsname);
+    }
+  }
+}
+
+bool 
+ContentFS::mount_props_mounted(const Props& props)
+{
+  if (props.has("mountpoint"))
+    return props.get("mountpoint").get_string().size();
+  return false;
+}
+
+
+
+
+  
+
+
+
 
 ContentFSTemplate::ContentFSTemplate(const String& name) :
   ContentTemplate(CONTENT_FS_TYPE),
-  name(name)
+  _name(name)
 {
-  attrs["fs_type"] = name;
+  attrs["fs_type"] = _name;
 }
 
 ContentFSTemplate::~ContentFSTemplate()
 {}
+
+
+
+void 
+ContentFSTemplate::mount_props_template(const String& fsname,
+					Props& props)
+{
+  bool mountable = ContentFS::mount_fs_supported(fsname);
+  props.set(Variable("mountable", mountable));
+  
+  if (mountable) {
+    list<String> illegal_mps = MountHandler().used_dirs();
+    props.set(Variable("mountpoint", 
+		       "", 
+		       0, 
+		       128, 
+		       ILLEGAL_MOUNT_CHARS, 
+		       illegal_mps));
+    props.set(Variable("fstab", false, true));
+    props.set(Variable("mount", false, true));
+  }
+}
+
+void 
+ContentFSTemplate::mount_props_create(const String& path,
+				      const String& fsname,
+				      const Props& props)
+{
+  if (props.has("mountpoint")) {
+    String mountpoint = props.get("mountpoint").get_string();
+    String label;
+    try {
+      label = props.get("label").get_string();
+    } catch ( ... ) {}
+    bool mount = props.get("mount").get_bool();
+    bool fstab = props.get("fstab").get_bool();
+    
+    if (mountpoint.size()) {
+      FstabLocker l;
+      if (mount)
+	MountHandler().mount(path, 
+			     mountpoint,
+			     fsname);
+      if (fstab)
+	MountHandler().fstab_add(label.empty() ? path : String("LABEL=") + label, 
+				 mountpoint,
+				 fsname);
+    }
+  }
+}
+
+
+
+
+
+bool
+ContentFS::mount_fs_supported(const String& fsname)
+{
+  list<String> l = MountHandler().fstypes();
+  if (find(l.begin(), l.end(), fsname) != l.end())
+    return true;
+  
+  String out, err;
+  int status;
+  vector<String> args;
+  args.push_back(fsname);
+  if (utils::execute("/sbin/modinfo", args, out, err, status))
+    throw String("execute failed");
+  return !status;
+}
ricci/modules/storage/ContentFS.h +26 -4
@@ -28,6 +28,9 @@
 #include "String.h"
 
 
+#define ILLEGAL_LABEL_CHARS    String(" <>?'\":;|}]{[)(*&^%$#@!~`+=")
+
+
 class ContentFS : public Content
 {
  public:
@@ -39,11 +42,23 @@
   virtual void remove();
   
   
- protected:
-  ContentFS(const String& name, const String& path);
-  String _name;
+  
+  static bool mount_fs_supported(const String& fsname); // true if mountable
+  // these fcns extract/place info from/into props
+  static bool mount_props_mounted(const Props& props); // true if mounted
+  static void mount_props_probe(const String& path,
+				const String& module,
+				Props& props);
+  static void mount_props_apply(const String& path,
+				const String& module,
+				const Props& old_props,
+				const Props& new_props);
   
   
+ protected:
+  ContentFS(const String& path, const String& name, const String& module);
+  String _name;
+  String _module;
   
 };
 
@@ -53,9 +68,16 @@
  public:
   virtual ~ContentFSTemplate();
   
+  static void mount_props_template(const String& module,
+				   Props &props);
+  static void mount_props_create(const String& path,
+				 const String& module,
+				 const Props &props);
+  
+  
  protected:
   ContentFSTemplate(const String& name);
-  String name;
+  String _name;
   
   
 };
ricci/modules/storage/ExtendedFS.cpp +54 -91

261 lines not on this page · raw message

ricci/modules/storage/ExtendedFS.h +1 -0
@@ -38,6 +38,7 @@
   ExtendedFS(const String& path);
   virtual ~ExtendedFS();
   
+  const static String PRETTY_NAME;
   
   virtual bool expandable(long long& max_size) const;
   virtual bool shrinkable(long long& min_size) const;
ricci/modules/storage/FSController.cpp +2 -10
@@ -39,14 +39,9 @@
   try {
     return counting_auto_ptr<Content>(new SwapFS(path));
   } catch ( ... ) {}
-  try {
-    //    return counting_auto_ptr<ContentFS>(new gfs(path));
-  } catch ( ... ) {}
   throw String("not FS");
-  
 }
 
-
 std::list<counting_auto_ptr<ContentTemplate> > 
 FSController::get_available_fss()
 {
@@ -58,9 +53,6 @@
   try {
     cnts.push_back(counting_auto_ptr<ContentTemplate>(new SwapFSTemplate()));
   } catch ( ... ) {}
-  try {
-    //    return counting_auto_ptr<ContentTemplate>(new gfsTemplate(path));
-  } catch ( ... ) {}
   
   return cnts;
 }
@@ -73,9 +65,9 @@
     throw String("content_template not of filesystem type");
   
   String fs_type = cont_templ->attrs["fs_type"];
-  if (fs_type == "extended_fs")
+  if (fs_type == ExtendedFS::PRETTY_NAME)
     create_extended_fs(bd->path(), cont_templ);
-  else if (fs_type == "swap")
+  else if (fs_type == SwapFS::PRETTY_NAME)
     create_swap_fs(bd->path(), cont_templ);
   else
     throw String("unknown fs type \"") + fs_type + "\"";
ricci/modules/storage/Props.cpp +6 -0
@@ -51,6 +51,12 @@
 {}
 
 
+bool 
+Props::has(const String& name) const
+{
+  return _vars.find(name) != _vars.end();
+}
+
 const Variable 
 Props::get(const String& name) const
 {
ricci/modules/storage/Props.h +2 -1
@@ -40,8 +40,9 @@
   Props(const XMLObject&);
   virtual ~Props();
   
-  const Variable get(const String& name) const;
   void set(const Variable& var);
+  bool has(const String& name) const;
+  const Variable get(const String& name) const;
   
   bool is_active(const Variable& var) const;
   
ricci/modules/storage/SwapFS.cpp +10 -2
@@ -31,8 +31,11 @@
 using namespace std;
 
 
+const String SwapFS::PRETTY_NAME("Swap");
+
+
 SwapFS::SwapFS(const String& path) :
-  ContentFS("swap", path)
+  ContentFS(path, PRETTY_NAME, "swap")
 {
   String magic(FileMagic::get_description(path));
   if (magic.find("swap") == magic.npos)
@@ -177,7 +180,12 @@
   ContentFSTemplate("swap")
 {
   // label
-  _props.set(Variable("label", "", 0, 16, illegal_label_chars, list<String>()));
+  _props.set(Variable("label", 
+		      "", 
+		      0, 
+		      16, 
+		      ILLEGAL_LABEL_CHARS, 
+		      list<String>()));
   
   // swapon
   _props.set(Variable("swapon", true, true));
ricci/modules/storage/SwapFS.h +1 -0
@@ -39,6 +39,7 @@
   SwapFS(const String& path);
   virtual ~SwapFS();
   
+  const static String PRETTY_NAME;
   
   virtual bool expandable(long long& max_size) const;
   virtual bool shrinkable(long long& min_size) const;
ricci/modules/storage/defines.h +0 -3
@@ -27,9 +27,6 @@
 #include "String.h"
 
 
-static String illegal_label_chars("| \\ /?.,");
-
-
 
 // XML tags for various objects