]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Monitor: use a single static accessor for getting CompatSet features off disk
authorGreg Farnum <greg@inktank.com>
Thu, 23 Jan 2014 01:15:56 +0000 (17:15 -0800)
committerGreg Farnum <greg@inktank.com>
Thu, 23 Jan 2014 23:32:03 +0000 (15:32 -0800)
This way we don't need to maintain two working code paths.

Signed-off-by: Greg Farnum <greg@inktank.com>
src/mon/Monitor.cc
src/mon/Monitor.h

index 6b88e9994f09c6c9dad643f8547bd6496b9966d7..b665b83b8bb205164e8c986a12afc4543f78a368 100644 (file)
@@ -322,43 +322,43 @@ int Monitor::check_features(MonitorDBStore *store)
   CompatSet required = get_supported_features();
   CompatSet ondisk;
 
-  bufferlist features;
-  store->get(MONITOR_NAME, COMPAT_SET_LOC, features);
-  if (features.length() == 0) {
+  read_features_off_disk(store, &ondisk);
+
+  if (!required.writeable(ondisk)) {
+    CompatSet diff = required.unsupported(ondisk);
+    generic_derr << "ERROR: on disk data includes unsupported features: " << diff << dendl;
+    return -EPERM;
+  }
+
+  return 0;
+}
+
+void Monitor::read_features_off_disk(MonitorDBStore *store, CompatSet *features)
+{
+  bufferlist featuresbl;
+  store->get(MONITOR_NAME, COMPAT_SET_LOC, featuresbl);
+  if (featuresbl.length() == 0) {
     generic_dout(0) << "WARNING: mon fs missing feature list.\n"
-           << "Assuming it is old-style and introducing one." << dendl;
+            << "Assuming it is old-style and introducing one." << dendl;
     //we only want the baseline ~v.18 features assumed to be on disk.
     //If new features are introduced this code needs to disappear or
     //be made smarter.
-    ondisk = get_legacy_features();
+    *features = get_legacy_features();
 
     bufferlist bl;
-    ondisk.encode(bl);
+    features->encode(bl);
     MonitorDBStore::Transaction t;
     t.put(MONITOR_NAME, COMPAT_SET_LOC, bl);
     store->apply_transaction(t);
   } else {
-    bufferlist::iterator it = features.begin();
-    ondisk.decode(it);
+    bufferlist::iterator it = featuresbl.begin();
+    features->decode(it);
   }
-
-  if (!required.writeable(ondisk)) {
-    CompatSet diff = required.unsupported(ondisk);
-    generic_derr << "ERROR: on disk data includes unsupported features: " << diff << dendl;
-    return -EPERM;
-  }
-
-  return 0;
 }
 
 void Monitor::read_features()
 {
-  bufferlist bl;
-  store->get(MONITOR_NAME, COMPAT_SET_LOC, bl);
-  assert(bl.length());
-
-  bufferlist::iterator p = bl.begin();
-  ::decode(features, p);
+  read_features_off_disk(store, &features);
   dout(10) << "features " << features << dendl;
 }
 
index be16da83af3949cb7635567180cc895dd487da5f..fcdb7ba977e5c571b12a413a14b1befeca59e426 100644 (file)
@@ -750,6 +750,8 @@ public:
   // features
   static CompatSet get_supported_features();
   static CompatSet get_legacy_features();
+  /// read the ondisk features into the CompatSet pointed to by read_features
+  static void read_features_off_disk(MonitorDBStore *store, CompatSet *read_features);
   void read_features();
   void write_features(MonitorDBStore::Transaction &t);